//
//  HomePageCollectionReusableView.m
//  JinMaJiaDemo
//
//  Created by GripMeMory on 16/2/16.
//  Copyright © 2016年 GripMeMory. All rights reserved.
//

#import "HomePageCollectionReusableView.h"
#import "ChannelViewController.h"

#define kRedBlockLeftMargin 15
#define kRedBlockWidth 5 / 2
#define kEnterLabelRightMargin 15
#define kTopMargin 5
#define kTitleLabelWidth 100
#define kRedBlockRightMargin 5

@implementation HomePageCollectionReusableView

{
    UIView *_redBlock;
    UILabel *_titleLabel;
    UILabel *_enterLabel;
}

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        _redBlock = [[UIView alloc] init];
        _titleLabel = [[UILabel alloc] init];
        _enterLabel = [[UILabel alloc] init];
        
        _enterLabel.text = @"进入频道》";
        
        [self addSubview:_redBlock];
        [self addSubview:_titleLabel];
        [self addSubview:_enterLabel];
    }
    return self;
}

- (void)layoutSubviews{
    
    _redBlock.frame = CGRectMake(kRedBlockLeftMargin, kTopMargin, kRedBlockWidth, self.height - kTopMargin);
    _titleLabel.frame = CGRectMake(_redBlock.right + kRedBlockRightMargin, kTopMargin, kTitleLabelWidth, _redBlock.height);
    _enterLabel.frame = CGRectMake(self.right - kTitleLabelWidth - kRedBlockLeftMargin, kTopMargin, kTitleLabelWidth, _redBlock.height);
    
    _redBlock.backgroundColor = [UIColor redColor];
    
    _titleLabel.textAlignment = NSTextAlignmentLeft;
    _titleLabel.adjustsFontSizeToFitWidth = YES;
    
    _enterLabel.textAlignment = NSTextAlignmentRight;
    _enterLabel.adjustsFontSizeToFitWidth = YES;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(enterChannel)];
    [_enterLabel addGestureRecognizer:tap];
    _enterLabel.userInteractionEnabled  = YES;
}

- (void)configureTitleWithString:(NSString *)titleString{
    _titleLabel.text = titleString;
}

- (void)enterChannel{
    
    ChannelViewController *newViewController = [[ChannelViewController alloc] init];
    [self.viewController.navigationController pushViewController:newViewController animated:NO];
    
}

@end
